/*!
 * @file  XYXKC_K210.h
 * @brief mind module for k210 visual module
 * @author xyxedu
 * @date 2014-4-12
 * @version 1.0.0
 */

#ifndef XYXKC_K210_H
#define XYXKC_K210_H
#include <Arduino.h>
#include "MyModbusCRC.h"
#include "XYXKC_Serial.h"
#include <SoftwareSerial.h>
#include <HardwareSerial.h>
#include <vector>
using namespace std;

#define BAUD_RATE 9600
#define FIRST_FRAME_HEADER 0x5a
#define SECOND_FRAME_HEADER 0xa5
#define INCREASE 0x69
#define DELETE 0x64
#define CHANGE 0x77
#define QUERY 0x71

#pragma pack(push, 1)
struct K210FunMSG {
    uint16_t x;
    uint16_t y;
    uint16_t w;
    uint16_t h;
    String msg;
};
#pragma pack(pop)
#pragma pack(push, 1)
struct K210MSG {
    uint16_t x;
    uint16_t y;
    uint16_t w;
    uint16_t h;
    String msg;
    uint16_t fun;
    bool isNewData;
};
#pragma pack(pop)

enum FrameIndex {
    HEADER1_INDEX = 0,
    HEADER2_INDEX,
    ALGORITHM_ID_INDEX,
    DATA_INDEX,
    CRC_INDEX,
    END_INDEX
};
enum CHANGE_ENUM {
    ALGORITHM_NUMBER = 0x01,
    FILL_IN_LIGHT = 0x02,
    BACKLIGHT = 0x03,
};

enum K210_FUNCTION_ENUM{
    ai_zero = 0,
    ai_face_recognition = 1,
    ai_or_code_recognition = 2,
    ai_barcode_recognition = 3,
    ai_findApriltagsFollow = 4,
    ai_findFacemaskFollow = 5,
    ai_findObjectFollow = 6,
    ai_findSignpostFollow = 7,
    ai_findDigitalCard = 8,
    ai_garbageSorting = 9,
    ai_findMultiColor = 10,
    ai_licenseplate = 11,
    ai_find_self_learning = 12

};

class XYXKC_K210 {
    public:
        XYXKC_K210();
        ~XYXKC_K210();
        void begin(SoftwareSerial *serial);
        void begin(HardwareSerial *serial);
        void begin(HardwareSerial *serial,int rxPin,int txPin);
        void retrieveDataOnce();
        bool parsingData(enum K210_FUNCTION_ENUM tag,K210FunMSG &funData);
        void algorithmSwitching(enum K210_FUNCTION_ENUM tag);
        void fillInLight(enum CHANGE_ENUM tag,  bool value);
        void saveImage();
        void getImageBase64();
        String getBase64();


    private:
        XYXKC_Serial _k210_Serial;
        K210MSG _data;
        String _imageBase64;

};
#endif //XYXKC_K210_H
